
const koa = require('koa');
const router = require('koa-router')();
const bodyP = require('koa-body');
const views = require('koa-views');
const static = require('koa-static');
const path=require('path');



let app = new koa();


//配置ejs模板要放在最前面
app.use(views('views', { map: { html: "ejs" } }))

app.use(bodyP());
//引用controller下的模块
const con=require('./controller');

// console.log("con:"+con);

//插入中间件
app.use(con());

//启动路由
app.use(router.routes());

//配置静态资源中间件
app.use(static(path.join( __dirname,'views')));


//使用中间件判断是否有当前路径
app.use(async (ctx, next) => {
    
    console.log("当前时间:" + new Date());

    if (ctx.status == 404) {
        ctx.body = "404界面"
    }
    await next();
});

let port = 3010;

app.listen(port, function () {
    console.log(`http://127.0.0.1:${port}`);
});